package com.heima.wemedia.fegin;

import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class WemediaClient implements IWemediaClient {

    private final WmUserService wmUserService;

    private final WmChannelService wmChannelService;

    @Override
    @GetMapping("/api/v1/wm_user/findByName/{name}")
    public WmUser findWmUserByName(@PathVariable String name) {
        return wmUserService.findWmUserByName(name);
    }

    @PostMapping("/api/v1/wm_user/saveWmUser")
    public void saveWmUser(@RequestBody WmUser wmUser) {
        wmUserService.saveWmUser(wmUser);
    }

    @Override
    @GetMapping("/api/v1/channel/list")
    public ResponseResult getChannels() {
        return wmChannelService.channels();
    }
}
